package comm.qf.springmvc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import comm.qf.springmvc.mapper.UserMapper;
import comm.qf.springmvc.pojo.User;
import comm.qf.springmvc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    private UserMapper userMapper;

    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    @Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
    public User findUserById(Long id) {
        return userMapper.findUserById(id);
    }

    @Override
    public PageInfo<User> findAllUser() {
        PageHelper.startPage(2,2);
        List<User> allUser=userMapper.findAllUser();
        return new PageInfo<>(allUser);
    }

    @Override
    @Transactional(noRollbackFor ={ArithmeticException.class} )
    public void updateUser(User user) {
        //开启事务
        userMapper.updateUserByIdwithSet(user);
        //提交事务

    }
}
